package com.situ.mymall.controller;


import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/page")
public class PageController {

    @RequestMapping("/**")
    public String path(HttpServletRequest request, Model model){
        String requestURI = request.getRequestURI();
        //这里在@before之后打印出来，requestURI为左侧点击的路径
        System.out.println("requestURI: " + requestURI);

        String queryString = request.getQueryString();
        String returnUri = queryString == null ? requestURI : requestURI + "?" + queryString;
        model.addAttribute("returnUri",returnUri);


        String[] paths = requestURI.split("/");

        if (paths.length == 4){
            return paths[2] + "_" + paths[3];
        } else if (paths.length == 3){
            return paths[2];
        } else {
            return "index";
        }

    }
}
